package qldc.pm.tienan.service.persistence;

import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.CharPool;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.UnmodifiableList;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import qldc.pm.tienan.NoSuchBienBanBanGiaoHoSoException;
import qldc.pm.tienan.model.BienBanBanGiaoHoSo;
import qldc.pm.tienan.model.impl.BienBanBanGiaoHoSoImpl;
import qldc.pm.tienan.model.impl.BienBanBanGiaoHoSoModelImpl;
import qldc.pm.tienan.service.persistence.BienBanBanGiaoHoSoPersistence;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the bien ban ban giao ho so service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see BienBanBanGiaoHoSoPersistence
 * @see BienBanBanGiaoHoSoUtil
 * @generated
 */
public class BienBanBanGiaoHoSoPersistenceImpl extends BasePersistenceImpl<BienBanBanGiaoHoSo>
    implements BienBanBanGiaoHoSoPersistence {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. Always use {@link BienBanBanGiaoHoSoUtil} to access the bien ban ban giao ho so persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
     */
    public static final String FINDER_CLASS_NAME_ENTITY = BienBanBanGiaoHoSoImpl.class.getName();
    public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List1";
    public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List2";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
            BienBanBanGiaoHoSoModelImpl.FINDER_CACHE_ENABLED,
            BienBanBanGiaoHoSoImpl.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
            BienBanBanGiaoHoSoModelImpl.FINDER_CACHE_ENABLED,
            BienBanBanGiaoHoSoImpl.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
            BienBanBanGiaoHoSoModelImpl.FINDER_CACHE_ENABLED, Long.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NGUOIDUOCBANGIAO_CHUCVU =
        new FinderPath(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
            BienBanBanGiaoHoSoModelImpl.FINDER_CACHE_ENABLED,
            BienBanBanGiaoHoSoImpl.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
            "findByNguoiDuocBanGiao_ChucVu",
            new String[] {
                String.class.getName(), String.class.getName(),
                
            Integer.class.getName(), Integer.class.getName(),
                OrderByComparator.class.getName()
            });
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_NGUOIDUOCBANGIAO_CHUCVU =
        new FinderPath(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
            BienBanBanGiaoHoSoModelImpl.FINDER_CACHE_ENABLED, Long.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
            "countByNguoiDuocBanGiao_ChucVu",
            new String[] { String.class.getName(), String.class.getName() });
    private static final String _FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_1 =
        "bienBanBanGiaoHoSo.nguoiDuocBanGiao LIKE NULL AND ";
    private static final String _FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_2 =
        "bienBanBanGiaoHoSo.nguoiDuocBanGiao LIKE ? AND ";
    private static final String _FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_3 =
        "(bienBanBanGiaoHoSo.nguoiDuocBanGiao IS NULL OR bienBanBanGiaoHoSo.nguoiDuocBanGiao LIKE '') AND ";
    private static final String _FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_1 =
        "bienBanBanGiaoHoSo.chucVuNguoiDuocBanGiao LIKE NULL";
    private static final String _FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_2 =
        "bienBanBanGiaoHoSo.chucVuNguoiDuocBanGiao LIKE ?";
    private static final String _FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_3 =
        "(bienBanBanGiaoHoSo.chucVuNguoiDuocBanGiao IS NULL OR bienBanBanGiaoHoSo.chucVuNguoiDuocBanGiao LIKE '')";
    private static final String _SQL_SELECT_BIENBANBANGIAOHOSO = "SELECT bienBanBanGiaoHoSo FROM BienBanBanGiaoHoSo bienBanBanGiaoHoSo";
    private static final String _SQL_SELECT_BIENBANBANGIAOHOSO_WHERE = "SELECT bienBanBanGiaoHoSo FROM BienBanBanGiaoHoSo bienBanBanGiaoHoSo WHERE ";
    private static final String _SQL_COUNT_BIENBANBANGIAOHOSO = "SELECT COUNT(bienBanBanGiaoHoSo) FROM BienBanBanGiaoHoSo bienBanBanGiaoHoSo";
    private static final String _SQL_COUNT_BIENBANBANGIAOHOSO_WHERE = "SELECT COUNT(bienBanBanGiaoHoSo) FROM BienBanBanGiaoHoSo bienBanBanGiaoHoSo WHERE ";
    private static final String _ORDER_BY_ENTITY_ALIAS = "bienBanBanGiaoHoSo.";
    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BienBanBanGiaoHoSo exists with the primary key ";
    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BienBanBanGiaoHoSo exists with the key {";
    private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
                PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
    private static Log _log = LogFactoryUtil.getLog(BienBanBanGiaoHoSoPersistenceImpl.class);
    private static BienBanBanGiaoHoSo _nullBienBanBanGiaoHoSo = new BienBanBanGiaoHoSoImpl() {
            @Override
            public Object clone() {
                return this;
            }

            @Override
            public CacheModel<BienBanBanGiaoHoSo> toCacheModel() {
                return _nullBienBanBanGiaoHoSoCacheModel;
            }
        };

    private static CacheModel<BienBanBanGiaoHoSo> _nullBienBanBanGiaoHoSoCacheModel =
        new CacheModel<BienBanBanGiaoHoSo>() {
            @Override
            public BienBanBanGiaoHoSo toEntityModel() {
                return _nullBienBanBanGiaoHoSo;
            }
        };

    public BienBanBanGiaoHoSoPersistenceImpl() {
        setModelClass(BienBanBanGiaoHoSo.class);
    }

    /**
     * Returns all the bien ban ban giao ho sos where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63;.
     *
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @return the matching bien ban ban giao ho sos
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<BienBanBanGiaoHoSo> findByNguoiDuocBanGiao_ChucVu(
        String nguoiDuocBanGiao, String chucVuNguoiDuocBanGiao)
        throws SystemException {
        return findByNguoiDuocBanGiao_ChucVu(nguoiDuocBanGiao,
            chucVuNguoiDuocBanGiao, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the bien ban ban giao ho sos where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tienan.model.impl.BienBanBanGiaoHoSoModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @param start the lower bound of the range of bien ban ban giao ho sos
     * @param end the upper bound of the range of bien ban ban giao ho sos (not inclusive)
     * @return the range of matching bien ban ban giao ho sos
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<BienBanBanGiaoHoSo> findByNguoiDuocBanGiao_ChucVu(
        String nguoiDuocBanGiao, String chucVuNguoiDuocBanGiao, int start,
        int end) throws SystemException {
        return findByNguoiDuocBanGiao_ChucVu(nguoiDuocBanGiao,
            chucVuNguoiDuocBanGiao, start, end, null);
    }

    /**
     * Returns an ordered range of all the bien ban ban giao ho sos where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tienan.model.impl.BienBanBanGiaoHoSoModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @param start the lower bound of the range of bien ban ban giao ho sos
     * @param end the upper bound of the range of bien ban ban giao ho sos (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching bien ban ban giao ho sos
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<BienBanBanGiaoHoSo> findByNguoiDuocBanGiao_ChucVu(
        String nguoiDuocBanGiao, String chucVuNguoiDuocBanGiao, int start,
        int end, OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NGUOIDUOCBANGIAO_CHUCVU;
        finderArgs = new Object[] {
                nguoiDuocBanGiao, chucVuNguoiDuocBanGiao,
                
                start, end, orderByComparator
            };

        List<BienBanBanGiaoHoSo> list = (List<BienBanBanGiaoHoSo>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (BienBanBanGiaoHoSo bienBanBanGiaoHoSo : list) {
                if (!StringUtil.wildcardMatches(
                            bienBanBanGiaoHoSo.getNguoiDuocBanGiao(),
                            nguoiDuocBanGiao, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true) ||
                        !StringUtil.wildcardMatches(
                            bienBanBanGiaoHoSo.getChucVuNguoiDuocBanGiao(),
                            chucVuNguoiDuocBanGiao, CharPool.UNDERLINE,
                            CharPool.PERCENT, CharPool.BACK_SLASH, true)) {
                    list = null;

                    break;
                }
            }
        }

        if (list == null) {
            StringBundler query = null;

            if (orderByComparator != null) {
                query = new StringBundler(4 +
                        (orderByComparator.getOrderByFields().length * 3));
            } else {
                query = new StringBundler(4);
            }

            query.append(_SQL_SELECT_BIENBANBANGIAOHOSO_WHERE);

            boolean bindNguoiDuocBanGiao = false;

            if (nguoiDuocBanGiao == null) {
                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_1);
            } else if (nguoiDuocBanGiao.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_3);
            } else {
                bindNguoiDuocBanGiao = true;

                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_2);
            }

            boolean bindChucVuNguoiDuocBanGiao = false;

            if (chucVuNguoiDuocBanGiao == null) {
                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_1);
            } else if (chucVuNguoiDuocBanGiao.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_3);
            } else {
                bindChucVuNguoiDuocBanGiao = true;

                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_2);
            }

            if (orderByComparator != null) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);
            } else
             if (pagination) {
                query.append(BienBanBanGiaoHoSoModelImpl.ORDER_BY_JPQL);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindNguoiDuocBanGiao) {
                    qPos.add(nguoiDuocBanGiao);
                }

                if (bindChucVuNguoiDuocBanGiao) {
                    qPos.add(chucVuNguoiDuocBanGiao);
                }

                if (!pagination) {
                    list = (List<BienBanBanGiaoHoSo>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<BienBanBanGiaoHoSo>(list);
                } else {
                    list = (List<BienBanBanGiaoHoSo>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Returns the first bien ban ban giao ho so in the ordered set where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63;.
     *
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching bien ban ban giao ho so
     * @throws qldc.pm.tienan.NoSuchBienBanBanGiaoHoSoException if a matching bien ban ban giao ho so could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo findByNguoiDuocBanGiao_ChucVu_First(
        String nguoiDuocBanGiao, String chucVuNguoiDuocBanGiao,
        OrderByComparator orderByComparator)
        throws NoSuchBienBanBanGiaoHoSoException, SystemException {
        BienBanBanGiaoHoSo bienBanBanGiaoHoSo = fetchByNguoiDuocBanGiao_ChucVu_First(nguoiDuocBanGiao,
                chucVuNguoiDuocBanGiao, orderByComparator);

        if (bienBanBanGiaoHoSo != null) {
            return bienBanBanGiaoHoSo;
        }

        StringBundler msg = new StringBundler(6);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("nguoiDuocBanGiao=");
        msg.append(nguoiDuocBanGiao);

        msg.append(", chucVuNguoiDuocBanGiao=");
        msg.append(chucVuNguoiDuocBanGiao);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchBienBanBanGiaoHoSoException(msg.toString());
    }

    /**
     * Returns the first bien ban ban giao ho so in the ordered set where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63;.
     *
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching bien ban ban giao ho so, or <code>null</code> if a matching bien ban ban giao ho so could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo fetchByNguoiDuocBanGiao_ChucVu_First(
        String nguoiDuocBanGiao, String chucVuNguoiDuocBanGiao,
        OrderByComparator orderByComparator) throws SystemException {
        List<BienBanBanGiaoHoSo> list = findByNguoiDuocBanGiao_ChucVu(nguoiDuocBanGiao,
                chucVuNguoiDuocBanGiao, 0, 1, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the last bien ban ban giao ho so in the ordered set where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63;.
     *
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching bien ban ban giao ho so
     * @throws qldc.pm.tienan.NoSuchBienBanBanGiaoHoSoException if a matching bien ban ban giao ho so could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo findByNguoiDuocBanGiao_ChucVu_Last(
        String nguoiDuocBanGiao, String chucVuNguoiDuocBanGiao,
        OrderByComparator orderByComparator)
        throws NoSuchBienBanBanGiaoHoSoException, SystemException {
        BienBanBanGiaoHoSo bienBanBanGiaoHoSo = fetchByNguoiDuocBanGiao_ChucVu_Last(nguoiDuocBanGiao,
                chucVuNguoiDuocBanGiao, orderByComparator);

        if (bienBanBanGiaoHoSo != null) {
            return bienBanBanGiaoHoSo;
        }

        StringBundler msg = new StringBundler(6);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("nguoiDuocBanGiao=");
        msg.append(nguoiDuocBanGiao);

        msg.append(", chucVuNguoiDuocBanGiao=");
        msg.append(chucVuNguoiDuocBanGiao);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchBienBanBanGiaoHoSoException(msg.toString());
    }

    /**
     * Returns the last bien ban ban giao ho so in the ordered set where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63;.
     *
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching bien ban ban giao ho so, or <code>null</code> if a matching bien ban ban giao ho so could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo fetchByNguoiDuocBanGiao_ChucVu_Last(
        String nguoiDuocBanGiao, String chucVuNguoiDuocBanGiao,
        OrderByComparator orderByComparator) throws SystemException {
        int count = countByNguoiDuocBanGiao_ChucVu(nguoiDuocBanGiao,
                chucVuNguoiDuocBanGiao);

        if (count == 0) {
            return null;
        }

        List<BienBanBanGiaoHoSo> list = findByNguoiDuocBanGiao_ChucVu(nguoiDuocBanGiao,
                chucVuNguoiDuocBanGiao, count - 1, count, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the bien ban ban giao ho sos before and after the current bien ban ban giao ho so in the ordered set where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63;.
     *
     * @param bienBanBanGiaoHoSoId the primary key of the current bien ban ban giao ho so
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next bien ban ban giao ho so
     * @throws qldc.pm.tienan.NoSuchBienBanBanGiaoHoSoException if a bien ban ban giao ho so with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo[] findByNguoiDuocBanGiao_ChucVu_PrevAndNext(
        long bienBanBanGiaoHoSoId, String nguoiDuocBanGiao,
        String chucVuNguoiDuocBanGiao, OrderByComparator orderByComparator)
        throws NoSuchBienBanBanGiaoHoSoException, SystemException {
        BienBanBanGiaoHoSo bienBanBanGiaoHoSo = findByPrimaryKey(bienBanBanGiaoHoSoId);

        Session session = null;

        try {
            session = openSession();

            BienBanBanGiaoHoSo[] array = new BienBanBanGiaoHoSoImpl[3];

            array[0] = getByNguoiDuocBanGiao_ChucVu_PrevAndNext(session,
                    bienBanBanGiaoHoSo, nguoiDuocBanGiao,
                    chucVuNguoiDuocBanGiao, orderByComparator, true);

            array[1] = bienBanBanGiaoHoSo;

            array[2] = getByNguoiDuocBanGiao_ChucVu_PrevAndNext(session,
                    bienBanBanGiaoHoSo, nguoiDuocBanGiao,
                    chucVuNguoiDuocBanGiao, orderByComparator, false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected BienBanBanGiaoHoSo getByNguoiDuocBanGiao_ChucVu_PrevAndNext(
        Session session, BienBanBanGiaoHoSo bienBanBanGiaoHoSo,
        String nguoiDuocBanGiao, String chucVuNguoiDuocBanGiao,
        OrderByComparator orderByComparator, boolean previous) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(6 +
                    (orderByComparator.getOrderByFields().length * 6));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_BIENBANBANGIAOHOSO_WHERE);

        boolean bindNguoiDuocBanGiao = false;

        if (nguoiDuocBanGiao == null) {
            query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_1);
        } else if (nguoiDuocBanGiao.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_3);
        } else {
            bindNguoiDuocBanGiao = true;

            query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_2);
        }

        boolean bindChucVuNguoiDuocBanGiao = false;

        if (chucVuNguoiDuocBanGiao == null) {
            query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_1);
        } else if (chucVuNguoiDuocBanGiao.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_3);
        } else {
            bindChucVuNguoiDuocBanGiao = true;

            query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_2);
        }

        if (orderByComparator != null) {
            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

            if (orderByConditionFields.length > 0) {
                query.append(WHERE_AND);
            }

            for (int i = 0; i < orderByConditionFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByConditionFields[i]);

                if ((i + 1) < orderByConditionFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
                    } else {
                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN);
                    } else {
                        query.append(WHERE_LESSER_THAN);
                    }
                }
            }

            query.append(ORDER_BY_CLAUSE);

            String[] orderByFields = orderByComparator.getOrderByFields();

            for (int i = 0; i < orderByFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByFields[i]);

                if ((i + 1) < orderByFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC_HAS_NEXT);
                    } else {
                        query.append(ORDER_BY_DESC_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC);
                    } else {
                        query.append(ORDER_BY_DESC);
                    }
                }
            }
        } else {
            query.append(BienBanBanGiaoHoSoModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Query q = session.createQuery(sql);

        q.setFirstResult(0);
        q.setMaxResults(2);

        QueryPos qPos = QueryPos.getInstance(q);

        if (bindNguoiDuocBanGiao) {
            qPos.add(nguoiDuocBanGiao);
        }

        if (bindChucVuNguoiDuocBanGiao) {
            qPos.add(chucVuNguoiDuocBanGiao);
        }

        if (orderByComparator != null) {
            Object[] values = orderByComparator.getOrderByConditionValues(bienBanBanGiaoHoSo);

            for (Object value : values) {
                qPos.add(value);
            }
        }

        List<BienBanBanGiaoHoSo> list = q.list();

        if (list.size() == 2) {
            return list.get(1);
        } else {
            return null;
        }
    }

    /**
     * Removes all the bien ban ban giao ho sos where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63; from the database.
     *
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeByNguoiDuocBanGiao_ChucVu(String nguoiDuocBanGiao,
        String chucVuNguoiDuocBanGiao) throws SystemException {
        for (BienBanBanGiaoHoSo bienBanBanGiaoHoSo : findByNguoiDuocBanGiao_ChucVu(
                nguoiDuocBanGiao, chucVuNguoiDuocBanGiao, QueryUtil.ALL_POS,
                QueryUtil.ALL_POS, null)) {
            remove(bienBanBanGiaoHoSo);
        }
    }

    /**
     * Returns the number of bien ban ban giao ho sos where nguoiDuocBanGiao LIKE &#63; and chucVuNguoiDuocBanGiao LIKE &#63;.
     *
     * @param nguoiDuocBanGiao the nguoi duoc ban giao
     * @param chucVuNguoiDuocBanGiao the chuc vu nguoi duoc ban giao
     * @return the number of matching bien ban ban giao ho sos
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countByNguoiDuocBanGiao_ChucVu(String nguoiDuocBanGiao,
        String chucVuNguoiDuocBanGiao) throws SystemException {
        FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_NGUOIDUOCBANGIAO_CHUCVU;

        Object[] finderArgs = new Object[] {
                nguoiDuocBanGiao, chucVuNguoiDuocBanGiao
            };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(3);

            query.append(_SQL_COUNT_BIENBANBANGIAOHOSO_WHERE);

            boolean bindNguoiDuocBanGiao = false;

            if (nguoiDuocBanGiao == null) {
                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_1);
            } else if (nguoiDuocBanGiao.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_3);
            } else {
                bindNguoiDuocBanGiao = true;

                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_NGUOIDUOCBANGIAO_2);
            }

            boolean bindChucVuNguoiDuocBanGiao = false;

            if (chucVuNguoiDuocBanGiao == null) {
                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_1);
            } else if (chucVuNguoiDuocBanGiao.equals(StringPool.BLANK)) {
                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_3);
            } else {
                bindChucVuNguoiDuocBanGiao = true;

                query.append(_FINDER_COLUMN_NGUOIDUOCBANGIAO_CHUCVU_CHUCVUNGUOIDUOCBANGIAO_2);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                if (bindNguoiDuocBanGiao) {
                    qPos.add(nguoiDuocBanGiao);
                }

                if (bindChucVuNguoiDuocBanGiao) {
                    qPos.add(chucVuNguoiDuocBanGiao);
                }

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Caches the bien ban ban giao ho so in the entity cache if it is enabled.
     *
     * @param bienBanBanGiaoHoSo the bien ban ban giao ho so
     */
    @Override
    public void cacheResult(BienBanBanGiaoHoSo bienBanBanGiaoHoSo) {
        EntityCacheUtil.putResult(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
            BienBanBanGiaoHoSoImpl.class, bienBanBanGiaoHoSo.getPrimaryKey(),
            bienBanBanGiaoHoSo);

        bienBanBanGiaoHoSo.resetOriginalValues();
    }

    /**
     * Caches the bien ban ban giao ho sos in the entity cache if it is enabled.
     *
     * @param bienBanBanGiaoHoSos the bien ban ban giao ho sos
     */
    @Override
    public void cacheResult(List<BienBanBanGiaoHoSo> bienBanBanGiaoHoSos) {
        for (BienBanBanGiaoHoSo bienBanBanGiaoHoSo : bienBanBanGiaoHoSos) {
            if (EntityCacheUtil.getResult(
                        BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
                        BienBanBanGiaoHoSoImpl.class,
                        bienBanBanGiaoHoSo.getPrimaryKey()) == null) {
                cacheResult(bienBanBanGiaoHoSo);
            } else {
                bienBanBanGiaoHoSo.resetOriginalValues();
            }
        }
    }

    /**
     * Clears the cache for all bien ban ban giao ho sos.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache() {
        if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
            CacheRegistryUtil.clear(BienBanBanGiaoHoSoImpl.class.getName());
        }

        EntityCacheUtil.clearCache(BienBanBanGiaoHoSoImpl.class.getName());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    /**
     * Clears the cache for the bien ban ban giao ho so.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache(BienBanBanGiaoHoSo bienBanBanGiaoHoSo) {
        EntityCacheUtil.removeResult(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
            BienBanBanGiaoHoSoImpl.class, bienBanBanGiaoHoSo.getPrimaryKey());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    @Override
    public void clearCache(List<BienBanBanGiaoHoSo> bienBanBanGiaoHoSos) {
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

        for (BienBanBanGiaoHoSo bienBanBanGiaoHoSo : bienBanBanGiaoHoSos) {
            EntityCacheUtil.removeResult(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
                BienBanBanGiaoHoSoImpl.class, bienBanBanGiaoHoSo.getPrimaryKey());
        }
    }

    /**
     * Creates a new bien ban ban giao ho so with the primary key. Does not add the bien ban ban giao ho so to the database.
     *
     * @param bienBanBanGiaoHoSoId the primary key for the new bien ban ban giao ho so
     * @return the new bien ban ban giao ho so
     */
    @Override
    public BienBanBanGiaoHoSo create(long bienBanBanGiaoHoSoId) {
        BienBanBanGiaoHoSo bienBanBanGiaoHoSo = new BienBanBanGiaoHoSoImpl();

        bienBanBanGiaoHoSo.setNew(true);
        bienBanBanGiaoHoSo.setPrimaryKey(bienBanBanGiaoHoSoId);

        return bienBanBanGiaoHoSo;
    }

    /**
     * Removes the bien ban ban giao ho so with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param bienBanBanGiaoHoSoId the primary key of the bien ban ban giao ho so
     * @return the bien ban ban giao ho so that was removed
     * @throws qldc.pm.tienan.NoSuchBienBanBanGiaoHoSoException if a bien ban ban giao ho so with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo remove(long bienBanBanGiaoHoSoId)
        throws NoSuchBienBanBanGiaoHoSoException, SystemException {
        return remove((Serializable) bienBanBanGiaoHoSoId);
    }

    /**
     * Removes the bien ban ban giao ho so with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param primaryKey the primary key of the bien ban ban giao ho so
     * @return the bien ban ban giao ho so that was removed
     * @throws qldc.pm.tienan.NoSuchBienBanBanGiaoHoSoException if a bien ban ban giao ho so with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo remove(Serializable primaryKey)
        throws NoSuchBienBanBanGiaoHoSoException, SystemException {
        Session session = null;

        try {
            session = openSession();

            BienBanBanGiaoHoSo bienBanBanGiaoHoSo = (BienBanBanGiaoHoSo) session.get(BienBanBanGiaoHoSoImpl.class,
                    primaryKey);

            if (bienBanBanGiaoHoSo == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
                }

                throw new NoSuchBienBanBanGiaoHoSoException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                    primaryKey);
            }

            return remove(bienBanBanGiaoHoSo);
        } catch (NoSuchBienBanBanGiaoHoSoException nsee) {
            throw nsee;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    @Override
    protected BienBanBanGiaoHoSo removeImpl(
        BienBanBanGiaoHoSo bienBanBanGiaoHoSo) throws SystemException {
        bienBanBanGiaoHoSo = toUnwrappedModel(bienBanBanGiaoHoSo);

        Session session = null;

        try {
            session = openSession();

            if (!session.contains(bienBanBanGiaoHoSo)) {
                bienBanBanGiaoHoSo = (BienBanBanGiaoHoSo) session.get(BienBanBanGiaoHoSoImpl.class,
                        bienBanBanGiaoHoSo.getPrimaryKeyObj());
            }

            if (bienBanBanGiaoHoSo != null) {
                session.delete(bienBanBanGiaoHoSo);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        if (bienBanBanGiaoHoSo != null) {
            clearCache(bienBanBanGiaoHoSo);
        }

        return bienBanBanGiaoHoSo;
    }

    @Override
    public BienBanBanGiaoHoSo updateImpl(
        qldc.pm.tienan.model.BienBanBanGiaoHoSo bienBanBanGiaoHoSo)
        throws SystemException {
        bienBanBanGiaoHoSo = toUnwrappedModel(bienBanBanGiaoHoSo);

        boolean isNew = bienBanBanGiaoHoSo.isNew();

        Session session = null;

        try {
            session = openSession();

            if (bienBanBanGiaoHoSo.isNew()) {
                session.save(bienBanBanGiaoHoSo);

                bienBanBanGiaoHoSo.setNew(false);
            } else {
                session.merge(bienBanBanGiaoHoSo);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

        if (isNew || !BienBanBanGiaoHoSoModelImpl.COLUMN_BITMASK_ENABLED) {
            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
        }

        EntityCacheUtil.putResult(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
            BienBanBanGiaoHoSoImpl.class, bienBanBanGiaoHoSo.getPrimaryKey(),
            bienBanBanGiaoHoSo);

        return bienBanBanGiaoHoSo;
    }

    protected BienBanBanGiaoHoSo toUnwrappedModel(
        BienBanBanGiaoHoSo bienBanBanGiaoHoSo) {
        if (bienBanBanGiaoHoSo instanceof BienBanBanGiaoHoSoImpl) {
            return bienBanBanGiaoHoSo;
        }

        BienBanBanGiaoHoSoImpl bienBanBanGiaoHoSoImpl = new BienBanBanGiaoHoSoImpl();

        bienBanBanGiaoHoSoImpl.setNew(bienBanBanGiaoHoSo.isNew());
        bienBanBanGiaoHoSoImpl.setPrimaryKey(bienBanBanGiaoHoSo.getPrimaryKey());

        bienBanBanGiaoHoSoImpl.setBienBanBanGiaoHoSoId(bienBanBanGiaoHoSo.getBienBanBanGiaoHoSoId());
        bienBanBanGiaoHoSoImpl.setKinhGui(bienBanBanGiaoHoSo.getKinhGui());
        bienBanBanGiaoHoSoImpl.setNguoiLap(bienBanBanGiaoHoSo.getNguoiLap());
        bienBanBanGiaoHoSoImpl.setNguoiDuocBanGiao(bienBanBanGiaoHoSo.getNguoiDuocBanGiao());
        bienBanBanGiaoHoSoImpl.setChucVu(bienBanBanGiaoHoSo.getChucVu());
        bienBanBanGiaoHoSoImpl.setChucVuNguoiDuocBanGiao(bienBanBanGiaoHoSo.getChucVuNguoiDuocBanGiao());
        bienBanBanGiaoHoSoImpl.setNoiDung(bienBanBanGiaoHoSo.getNoiDung());
        bienBanBanGiaoHoSoImpl.setNgayLap(bienBanBanGiaoHoSo.getNgayLap());
        bienBanBanGiaoHoSoImpl.setNgayBanGiao(bienBanBanGiaoHoSo.getNgayBanGiao());
        bienBanBanGiaoHoSoImpl.setDiaDiemBanGiao(bienBanBanGiaoHoSo.getDiaDiemBanGiao());

        return bienBanBanGiaoHoSoImpl;
    }

    /**
     * Returns the bien ban ban giao ho so with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
     *
     * @param primaryKey the primary key of the bien ban ban giao ho so
     * @return the bien ban ban giao ho so
     * @throws qldc.pm.tienan.NoSuchBienBanBanGiaoHoSoException if a bien ban ban giao ho so with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo findByPrimaryKey(Serializable primaryKey)
        throws NoSuchBienBanBanGiaoHoSoException, SystemException {
        BienBanBanGiaoHoSo bienBanBanGiaoHoSo = fetchByPrimaryKey(primaryKey);

        if (bienBanBanGiaoHoSo == null) {
            if (_log.isWarnEnabled()) {
                _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }

            throw new NoSuchBienBanBanGiaoHoSoException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                primaryKey);
        }

        return bienBanBanGiaoHoSo;
    }

    /**
     * Returns the bien ban ban giao ho so with the primary key or throws a {@link qldc.pm.tienan.NoSuchBienBanBanGiaoHoSoException} if it could not be found.
     *
     * @param bienBanBanGiaoHoSoId the primary key of the bien ban ban giao ho so
     * @return the bien ban ban giao ho so
     * @throws qldc.pm.tienan.NoSuchBienBanBanGiaoHoSoException if a bien ban ban giao ho so with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo findByPrimaryKey(long bienBanBanGiaoHoSoId)
        throws NoSuchBienBanBanGiaoHoSoException, SystemException {
        return findByPrimaryKey((Serializable) bienBanBanGiaoHoSoId);
    }

    /**
     * Returns the bien ban ban giao ho so with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param primaryKey the primary key of the bien ban ban giao ho so
     * @return the bien ban ban giao ho so, or <code>null</code> if a bien ban ban giao ho so with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo fetchByPrimaryKey(Serializable primaryKey)
        throws SystemException {
        BienBanBanGiaoHoSo bienBanBanGiaoHoSo = (BienBanBanGiaoHoSo) EntityCacheUtil.getResult(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
                BienBanBanGiaoHoSoImpl.class, primaryKey);

        if (bienBanBanGiaoHoSo == _nullBienBanBanGiaoHoSo) {
            return null;
        }

        if (bienBanBanGiaoHoSo == null) {
            Session session = null;

            try {
                session = openSession();

                bienBanBanGiaoHoSo = (BienBanBanGiaoHoSo) session.get(BienBanBanGiaoHoSoImpl.class,
                        primaryKey);

                if (bienBanBanGiaoHoSo != null) {
                    cacheResult(bienBanBanGiaoHoSo);
                } else {
                    EntityCacheUtil.putResult(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
                        BienBanBanGiaoHoSoImpl.class, primaryKey,
                        _nullBienBanBanGiaoHoSo);
                }
            } catch (Exception e) {
                EntityCacheUtil.removeResult(BienBanBanGiaoHoSoModelImpl.ENTITY_CACHE_ENABLED,
                    BienBanBanGiaoHoSoImpl.class, primaryKey);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return bienBanBanGiaoHoSo;
    }

    /**
     * Returns the bien ban ban giao ho so with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param bienBanBanGiaoHoSoId the primary key of the bien ban ban giao ho so
     * @return the bien ban ban giao ho so, or <code>null</code> if a bien ban ban giao ho so with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public BienBanBanGiaoHoSo fetchByPrimaryKey(long bienBanBanGiaoHoSoId)
        throws SystemException {
        return fetchByPrimaryKey((Serializable) bienBanBanGiaoHoSoId);
    }

    /**
     * Returns all the bien ban ban giao ho sos.
     *
     * @return the bien ban ban giao ho sos
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<BienBanBanGiaoHoSo> findAll() throws SystemException {
        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the bien ban ban giao ho sos.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tienan.model.impl.BienBanBanGiaoHoSoModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of bien ban ban giao ho sos
     * @param end the upper bound of the range of bien ban ban giao ho sos (not inclusive)
     * @return the range of bien ban ban giao ho sos
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<BienBanBanGiaoHoSo> findAll(int start, int end)
        throws SystemException {
        return findAll(start, end, null);
    }

    /**
     * Returns an ordered range of all the bien ban ban giao ho sos.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.tienan.model.impl.BienBanBanGiaoHoSoModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of bien ban ban giao ho sos
     * @param end the upper bound of the range of bien ban ban giao ho sos (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of bien ban ban giao ho sos
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<BienBanBanGiaoHoSo> findAll(int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
                (orderByComparator == null)) {
            pagination = false;
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
            finderArgs = FINDER_ARGS_EMPTY;
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
            finderArgs = new Object[] { start, end, orderByComparator };
        }

        List<BienBanBanGiaoHoSo> list = (List<BienBanBanGiaoHoSo>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if (list == null) {
            StringBundler query = null;
            String sql = null;

            if (orderByComparator != null) {
                query = new StringBundler(2 +
                        (orderByComparator.getOrderByFields().length * 3));

                query.append(_SQL_SELECT_BIENBANBANGIAOHOSO);

                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);

                sql = query.toString();
            } else {
                sql = _SQL_SELECT_BIENBANBANGIAOHOSO;

                if (pagination) {
                    sql = sql.concat(BienBanBanGiaoHoSoModelImpl.ORDER_BY_JPQL);
                }
            }

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                if (!pagination) {
                    list = (List<BienBanBanGiaoHoSo>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<BienBanBanGiaoHoSo>(list);
                } else {
                    list = (List<BienBanBanGiaoHoSo>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Removes all the bien ban ban giao ho sos from the database.
     *
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeAll() throws SystemException {
        for (BienBanBanGiaoHoSo bienBanBanGiaoHoSo : findAll()) {
            remove(bienBanBanGiaoHoSo);
        }
    }

    /**
     * Returns the number of bien ban ban giao ho sos.
     *
     * @return the number of bien ban ban giao ho sos
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countAll() throws SystemException {
        Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
                FINDER_ARGS_EMPTY, this);

        if (count == null) {
            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(_SQL_COUNT_BIENBANBANGIAOHOSO);

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Initializes the bien ban ban giao ho so persistence.
     */
    public void afterPropertiesSet() {
        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
                    com.liferay.util.service.ServiceProps.get(
                        "value.object.listener.qldc.pm.tienan.model.BienBanBanGiaoHoSo")));

        if (listenerClassNames.length > 0) {
            try {
                List<ModelListener<BienBanBanGiaoHoSo>> listenersList = new ArrayList<ModelListener<BienBanBanGiaoHoSo>>();

                for (String listenerClassName : listenerClassNames) {
                    listenersList.add((ModelListener<BienBanBanGiaoHoSo>) InstanceFactory.newInstance(
                            getClassLoader(), listenerClassName));
                }

                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
            } catch (Exception e) {
                _log.error(e);
            }
        }
    }

    public void destroy() {
        EntityCacheUtil.removeCache(BienBanBanGiaoHoSoImpl.class.getName());
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }
}
